package com.rdc.qingkou.model;

import com.rdc.qingkou.contract.LogoutContract;
import com.rdc.qingkou.entity.Result;
import com.rdc.qingkou.model.imodel.OnHttpCallBack;
import com.rdc.qingkou.retrofitService.IPersonalSettingsService;
import com.rdc.qingkou.utils.MyUtils;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by WaxBerry on 2017/11/20.
 */

public class LogoutModel implements LogoutContract.IModel {
    @Override
    public void logout(final OnHttpCallBack<Result> callBack) {

        MyUtils.getRetrofitProvider("")
                .create(IPersonalSettingsService.class)
                .logout()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new Observer<Result>() {

                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                    }

                    @Override
                    public void onNext(Result result) {
                        callBack.onSuccessful(result);
                    }

                    @Override
                    public void onError(Throwable t) {
                        t.printStackTrace();
                    }

                    @Override
                    public void onComplete() {
                    }
                });
    }
}
